You are NOT allowed to access internet for both questions.

The code for both questions is simpler than the ones in the previous quiz. DO NOT overthink !

Restrictions : As usual only solutions using list comprehension will be appreciated.

Q1

Consider a unit square with vertices (0, 0), (0, 1), (1, 1), (1, 0). If two points are picked randomly within the square calculate the average distance between them. Hints : You may need to use.........

Generating random points

import random random.uniform(start, stop)

Returns a float number between start and stop.

random.uniform(0, 1) --> 0.2967783156262709 random.uniform(0, 1) --> 0.5677612555662909

Summing up all numbers in a list

lst = [0, 1, 2, 3, 4] sum(lst) --> 10

Square root

from math import sqrt

sqrt(5) --> 2.23606797749979 sqrt(4) --> 4.0

Q2

Monte Carlo method is a very powerful technique to generate interesting results. Now don't get your brain baked on this. This is an extremely simple example of Monte Carlo method and you needn't be familiar with the term at all. Write a program to approximate the value of pi. How to do this using method mentioned above ? Consider a unit square with a unit radius circle in it. If points are randomly chosen in the combined figure some will lie in the circle and others will lie outside it. Now think about how the value of pi can be computed from this information.

Hints : You may need to use.........

import random random.uniform(start, stop)

Returns a float number between start and stop.

random.uniform(0, 1) --> 0.2967783156262709 random.uniform(0, 1) --> 0.5677612555662909

If anymore hints are given, it will be like telling you the answer....